/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.hazardsource.controller;

import com.koron.hazardsource.util.BusinessCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.swan.bean.MessageBean;

import com.koron.common.StaffAttribute;
import com.koron.common.bean.StaffBean;
import com.koron.common.permission.SPIAccountAnno;
import com.koron.hazardsource.service.api.PracticeTemplateService;
import com.koron.system.annotation.Log;
import com.koron.system.discrete.BusinessManipulation;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "practiceTemplate",description = "网格模板")
@RestController
@RequestMapping("/template")
public class PracticeTemplateController {

	@Autowired
	private PracticeTemplateService service;

	@ApiOperation("新增网格模板")
	@ApiImplicitParams({
        @ApiImplicitParam(name = "name", value = "名称", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "serial", value = "排序号",  paramType = "query", dataType = "Integer"),
        @ApiImplicitParam(name = "templateType", value = "模板类型", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "pid", value = "父id",  paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "remark", value = "备注",  paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/save.htm", method = { RequestMethod.POST })
    @Log(title = "新增网格模板", businessModule = "网格模板", businessManipulation = BusinessManipulation.INSERT)
	public MessageBean<?> save(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,String name, Integer serial, String templateType, String pid, String remark){
		if(user==null){
			MessageBean<?>msg=new MessageBean<>();
			msg.setCode(BusinessCode.MESSAGE_CODE_ACTION_EXCEPTION);
			msg.setDescription(BusinessCode.MESSAGE_DESCRIPTION_ACTION_EXCEPTION);
			return msg;
		}
		return service.save(user, name, serial, templateType, pid, remark);
	}

	@ApiOperation("修改网格模板")
	@ApiImplicitParams({
        @ApiImplicitParam(name = "name", value = "名称", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "serial", value = "排序号",  paramType = "query", dataType = "Integer"),
        @ApiImplicitParam(name = "remark", value = "备注",  paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/update.htm", method = { RequestMethod.POST })
    @Log(title = "修改网格模板", businessModule = "网格模板", businessManipulation = BusinessManipulation.UPDATE)
	public MessageBean<?> update(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,String id,String name, Integer serial,String remark,Integer subnumber){
		if(user==null){
			MessageBean<?>msg=new MessageBean<>();
			msg.setCode(BusinessCode.MESSAGE_CODE_ACTION_EXCEPTION);
			msg.setDescription(BusinessCode.MESSAGE_DESCRIPTION_ACTION_EXCEPTION);
			return msg;
		}
		return service.update(user, id, name, serial, remark,subnumber);
	}

	@ApiOperation("删除网格模板")
	@ApiImplicitParam(name = "id", value = "id",  paramType = "query", dataType = "String")
    @RequestMapping(value = "/delete.htm", method = { RequestMethod.POST })
    @Log(title = "删除网格模板", businessModule = "网格模板", businessManipulation = BusinessManipulation.DELETE)
	public MessageBean<?> delete(String id){
		return service.delete(id);
	}

	@ApiOperation("详情")
	@ApiImplicitParam(name = "id", value = "id",  paramType = "query", dataType = "String")
    @RequestMapping(value = "/details.htm", method = { RequestMethod.GET })
	public MessageBean<?> details(String id){
		return service.details(id);
	}

	@ApiOperation("列表")
	@ApiImplicitParams({
        @ApiImplicitParam(name = "templateType", value = "模板类型", required = true, paramType = "query", dataType = "String"),
        @ApiImplicitParam(name = "id", value = "id",  paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/list.htm", method = { RequestMethod.GET })
	public MessageBean<?> list(String templateType,String id){
		return service.list(templateType, id);
	}

	@ApiOperation("子集")
	@ApiImplicitParam(name = "id", value = "id",  paramType = "query", dataType = "String")
    @RequestMapping(value = "/childList.htm", method = { RequestMethod.GET })
	public MessageBean<?> childList(String id){
		return service.childList(id);
	}

	@ApiOperation("所有列表")
	@ApiImplicitParam(name = "templateType", value = "模板类型", required = true, paramType = "query", dataType = "String")
    @RequestMapping(value = "/allList.htm", method = { RequestMethod.GET })
	public MessageBean<?> allList(String templateType,String id){
		return service.allList(templateType);
	}
}
